<include file='Admin/Tpl/Public/nav.html' />
<div class="the-box full no-border">
<div class="sidebar-right-heading">
      <ul class="nav nav-tabs square nav-justified">
            <li class="active"><a href="#online-user-sidebar" data-toggle="tab"><i class="fa fa-comments"></i></a></li>
            <li><a href="#notification-sidebar" data-toggle="tab"><i class="fa fa-bell"></i></a></li>
            <li><a href="#task-sidebar" data-toggle="tab"><i class="fa fa-tasks"></i></a></li>
            <li><a href="#setting-sidebar" data-toggle="tab"><i class="fa fa-cogs"></i></a></li>
      </ul>
</div><!-- /.sidebar-right-heading -->
<div class="page-content">
      <div class="container-fluid">
   		<h1 class="page-heading">Team In <small>地址管理</small></h1>            
            <h5 class="small-title">新地址添加</h5>
            <a href="__URL__/index" class="btn btn-success">返回地址列表</a>

		<div class="table-responsive">
			<div class="the-box">
				<form id="ExampleBootstrapValidationForm" method="post" action="__URL__/addAct" class="form-horizontal" enctype="multipart/form-data">
					<fieldset>
						
						<div class="form-group">
							<label class="col-lg-3 control-label">城市 <span style="color:red">*</span></label>
							<div class="col-lg-5">
								<select class="form-control change_local" tabindex="2" name="local_id" id="select" onchange="change_build()">
									<foreach name="local" item="value">
										<option value="{$value.local_id}">{$value.local_name}</option>
									</foreach>														
								</select>
								<a  id="city_add" class="bcf_add btn btn-primary btn-lg" style="padding:3px;" role="button">添加新城市</a>												
							</div>

						</div>	
						<div class="form-group">
							<label class="col-lg-3 control-label">楼名 <span style="color:red">*</span></label>
							<div class="col-lg-5">											
								<select class="form-control change_build" tabindex="2" name="building_id" id="select">
									<foreach name="build" item="value">
										<option value="{$value.building_id}">{$value.building_name}</option>
									</foreach>														
								</select>
								<a  id="build_add" class="bcf_add btn btn-primary btn-lg" style="padding:3px;" role="button">添加新楼</a>
							</div>
						</div>
						<div class="form-group">
							<label class="col-lg-3 control-label">楼层 <span style="color:red">*</span></label>
							<div class="col-lg-5">
								<input placeholder="请填写楼层名称" type="text" class="form-control must" id="name" type="text" name="floor_name" />
							</div>

						</div>	
					</fieldset>					
													
					<div class="form-group">
						<div class="col-lg-9 col-lg-offset-3">									
							<input class="btn btn-success" id="submit"  type="submit" value="填写完成提交" />
						</div>
					</div>
				</form>
			</div>

			<!--城市添加-->
			<div class="add_bg" style="display:none;background:black;opacity:0.3;position:absolute;z-index:50;top:0px;left:0px;bottom:0px;width:100%;height:"></div>					
			<div class="add_data add_city the-box" style="display:none;border-radius:3px;position:absolute;z-index:100;left:30%;top:30%;" >
				<div class="sub sub_remove" style="float:right;font-size:25px;margin-top:-15px;">x</div>
				<h4 id="title_name">城市添加:</h4>
				<div class="input">
					<select class="form-control local_id_for_build" tabindex="2" name="local_id" id="select">
						<foreach name="local" item="value">
							<option value="{$value.local_id}">{$value.local_name}</option>
						</foreach>														
					</select><br />
					<input placeholder='请填写楼名'  class='building_name form-control must' id='position' type='text' name='building_name' />
				</div>	
				<br />
				<div style="float:left;margin-right:5px;" class="sub sub_add btn btn-info">添加</div>
				<div style="float:left;" class="sub sub_remove btn btn-danger">取消</div>
			</div>
			<!--城市添加结束-->
									
		</div><!-- /.table-responsive -->
	</div><!-- /.the-box -->
</div>

<script>
//判断提交内容
	$("#submit").click(function(){
		if($("input[name='floor_name']").val()==""){
			return false;
		}
		
	});
	$(".bcf_add").click(function(){
		var name_add = $(this).attr('id');
		switch(name_add){
			case "city_add":
				$("#title_name").text("城市添加:");
				$(".input").html("<input style='margin-bottom:5px' class='local_name form-control must' id='local' type='text' name='local_name' />");							
				$(".add_bg").css({display:"block"});
				$(".add_city").css({display:"block"});
			break;
			case "build_add":
				$("#title_name").text("楼座添加:");				
				$(".add_bg").css({display:"block"});
				$(".add_city").css({display:"block"});
			break;			
		}		
	});

	$(".sub_remove").click(function(){
		$(".add_bg").css({display:"none"});
		$(".add_city").css({display:"none"});
	});
	//添加城市
	$(".sub_add").click(function(){
		var name = $(this).parent().find(".form-control").val();
		var data = $(this).parent().find("input").attr('name');
		switch(data){			
			case "local_name":
				if(name !=""){
					$.ajax({
						url:"__URL__/add_city",
						type:"post",
						data:{"local_name":name},
						success:function(data){
							$('.add_data').html(data);
							$('.back').click(function(){
								window.location="__SELF__";
							});							
						}
					});
				}else{
					$(this).parent().find(".local_name").css({border:"2px solid red"});
				}
			break;
			case "building_name":
				if(name !=""){
					$.ajax({
						url:"__URL__/add_build",
						type:"post",
						data:{
							building_name:$('[name="building_name"]').val(),
							local_id:$('.local_id_for_build').val()
						},
						success:function(data){
							$('.add_data').html(data);
							$('.back').click(function(){
								window.location="__SELF__";
							});							
						}
					});
				}else{
					$(this).parent().find(".building_name").css({border:"2px solid red"});
				}
			break;			
		}
		
	});
function change_build()
{
	$('.change_local').val();
	$.ajax({
		url:"__URL__/get_build",
		type:"post",
		dataType:"json",
		data:{
			local_id:$('.change_local').val()
		},
		success:function(data){
			if(data.state == 0)
			{
				var $option = '';
				for(var $i=0;$i<data.data.length;$i++)
				{
					$option+='<option value="'+data.data[$i].building_id+'">'+data.data[$i].building_name+'</option>';	
				}
				$('.change_build').html($option);
			}else{
				$('.change_build').html('');
			}					
		}
	});
		
}
</script>